package com.cskaoyan.service;

import com.cskaoyan.bean.MarketComment;
import com.cskaoyan.bean.bo.AdminCommentListBO;
import com.cskaoyan.bean.bo.CommentReplyBO;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketCommentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : gao
 * @since: 2022/10/13  11:15
 */
@Service
public class AdminCommentServiceImpl implements AdminCommentService {
    @Autowired
    MarketCommentMapper marketCommentMapper;

    @Override
    public CommonData<MarketComment> list(AdminCommentListBO adminCommentListBO) {

        Integer page = adminCommentListBO.getPage();
        Integer limit = adminCommentListBO.getLimit();

        PageHelper.startPage(page, limit);
        List<MarketComment> commentList = marketCommentMapper.queryList(adminCommentListBO);
        PageInfo<MarketComment> pageInfo = new PageInfo<>(commentList);

        CommonData<MarketComment> data = new CommonData<>();
        data.setTotal((int) pageInfo.getTotal());
        data.setPages(pageInfo.getPages());
        data.setLimit(limit);
        data.setPage(page);
        data.setList(commentList);

        return data;
    }

    /**
     * 删除评论
     *
     * @return {@link null}
     * @author gao
     * @since 2022/10/13 14:20
     */
    @Override
    public void deleteComment(Integer id) {
        marketCommentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public boolean reply(CommentReplyBO commentReplyBO) {
        Integer commentId = commentReplyBO.getCommentId();
        String replyContent = marketCommentMapper.selectReplyCommentById(commentId);


        if (replyContent.equals("")) {
            //该订单还未回复，回复评论
            marketCommentMapper.updateCommentById(commentReplyBO);
            return false;
        }
            //该订单已回复
            return true;


    }

}
